package org.redr.widgetGUI.core;

import org.redr.widgetGUI.settings.WidgetSettings;
import org.redr.widgetGUI.settings.WidgetState;

import com.trolltech.qt.gui.QDoubleSpinBox;
import com.trolltech.qt.gui.QLabel;

public class SpinBox extends WidgetState{
	private QDoubleSpinBox spinBox;
	
	public QDoubleSpinBox widget(){
		return spinBox;
	}
	
	public SpinBox(LayoutState p, WidgetSettings ws){
		super(p, ws);
		p.addWidget(new QLabel(_getSetting("label", "!!FIX ME LABEL SHOULD BE SET!!")));
		spinBox	=	new QDoubleSpinBox();
		p.addWidget(spinBox);
		_setDecimal();
		_setMin();
		_setMax();
		_setValue();
	}
	
	private void _setValue() {
		// TODO Auto-generated method stub
		
	}

	private void _setDecimal(){
		try{
			Integer decimal	=	Integer.parseInt(_getSetting("decimal", "0"));
			spinBox.setDecimals(decimal);
		} catch (Exception e){
			e.printStackTrace();
		}
	}
	
	private void _setMin(){
		try{
			String setting	=	_getSetting("decimal", "NaN");
			if (setting.equals("NaN")) return;
			Integer decimal	=	Integer.parseInt(setting);
			spinBox.setMinimum(decimal);
		} catch (Exception e){
			e.printStackTrace();
		}
	}
	
	private void _setMax(){
		try{
			String setting	=	_getSetting("decimal", "NaN");
			if (setting.equals("NaN")) return;
			Integer decimal	=	Integer.parseInt(setting);
			spinBox.setMaximum(decimal);
		} catch (Exception e){
			e.printStackTrace();
		}
	}

}
